<!-- 沥青技术要求 -->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"
      style="display: flex;justify-content: space-between;">
      <div>
        <el-form-item label="项目名称" prop="deptId">
          <el-select clearable style="width: 150px;" v-model="queryParams.deptId" placeholder="请选择项目名称">
            <el-option v-for="item in deptList" :key="item.id" :label="item.label"
              :value="item.id.toString()"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="样品名称" prop="name">
          <el-input v-model="queryParams.name" placeholder="样品名称" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>

        <el-form-item label="沥青种类" prop="asphaltVariety">
          <el-select v-model="queryParams.asphaltVariety" @change="dictSelectChange" placeholder="请选择沥青种类" clearable
            @keyup.enter.native="handleQuery" style="width: 100%;">
            <el-option v-for="dict in dict.type.asphalt_variety" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="沥青标号" prop="asphaltLabel">
          <el-select v-model="queryParams.asphaltLabel" placeholder="请选择沥青标号" clearable @keyup.enter.native="handleQuery"
            style="width: 100%;">
            <el-option v-for="dict in dictVal" :key="dict.dictValue" :label="dict.dictLabel"
              :value="dict.dictLabel"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"
            v-hasPermi="['xtcsgl:asphalt:query']">搜索</el-button>
          <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> -->
        </el-form-item>
      </div>

      <el-form-item>
        <el-button type="success" icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['xtcsgl:asphalt:add']">新增沥青技术要求</el-button>
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5"><el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['xtcsgl:asphalt:add']">新增沥青技术要求</el-button></el-col>
    </el-row> -->

    <el-table border v-loading="loading" :data="asphaltList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="45" align="center" /> -->
      <el-table-column label="序号" type="index" align="center" />
      <el-table-column label="项目名称" align="center" prop="deptName" />
      <el-table-column label="样品名称" align="center" prop="name" min-width="145" show-overflow-tooltip />
      <el-table-column label="样品型号" align="center" min-width="145" show-overflow-tooltip>
        <template slot-scope="scope"><span>{{ scope.row.asphaltVariety + scope.row.asphaltLabel || " "
        }}</span></template>
      </el-table-column>
      <el-table-column label="针入度" align="center" prop="penetration" min-width="220" show-overflow-tooltip />
      <el-table-column label="延度" align="center" prop="ductility" min-width="220" show-overflow-tooltip />
      <el-table-column label="软化点" align="center" prop="softDesc" min-width="130" show-overflow-tooltip />
      <el-table-column label="采集时间" align="center" prop="insertTime" width="135">
        <template slot-scope="scope"><span>{{ parseTime(scope.row.insertTime, '{y}-{m}-{d}') }}</span></template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['xtcsgl:asphalt:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row, scope.$index)"
            v-hasPermi="['xtcsgl:asphalt:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改沥青技术要求对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row :gutter="20">

          <el-col :span="8">
            <el-form-item label="项目名称" prop="deptId">
              <el-select v-model="form.deptId" placeholder="请选择项目名称" style="width: 100%;">
                <el-option v-for="item in deptList" :key="item.id" :label="item.label" :value="item.id.toString()">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="沥青种类" prop="asphaltVariety">
              <el-select v-model="form.asphaltVariety" @change="dictSelectChange" clearable placeholder="沥青种类"
                style="width: 100%;">
                <el-option v-for="dict in dict.type.asphalt_variety" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="沥青标号" prop="asphaltLabel">
              <el-select v-model="form.asphaltLabel" placeholder="沥青标号" clearable style="width: 100%;">
                <el-option v-for="dict in dictVal" :key="dict.dictValue" :label="dict.dictLabel"
                  :value="dict.dictLabel"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 针入度 -->
        <div style="margin-top: 20px;">
          <span style="margin: 20px 0 8px 0;font-weight: 900;font-size: 18px">针入度技术要求</span>
          <div class="display-right-btn">
            <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddPenetration"></el-button>
          </div>
          <el-table border stripe class="table" v-loading="loading" style="width: 100%" :data="form.refs">
            <el-table-column label="序号" type="index" align="center" />
            <el-table-column label="温度(℃)" align="center" prop="temperature">
              <template slot-scope="scope">
                <el-input v-model="scope.row.temperature" placeholder="请输入" maxlength="40"></el-input>
              </template>
            </el-table-column>

            <el-table-column label="针入度上限(0.1mm)" align="center" prop="max">
              <template slot-scope="scope">
                <el-input v-model="scope.row.max" placeholder="请输入" maxlength="40"></el-input>
              </template>
            </el-table-column>

            <el-table-column label="针入度下限(0.1mm)" align="center" prop="min">
              <template slot-scope="scope">
                <el-input v-model="scope.row.min" placeholder="请输入" maxlength="40"></el-input>
              </template>
            </el-table-column>

            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
              <template slot-scope="scope">
                <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete1(scope.row, scope.$index)"
                  v-hasPermi="['xtcsgl:asphalt:remove']">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <!-- 软化点 -->
        <div style="margin-top: 20px;">
          <span style="margin: 20px 0 8px 0;font-weight: 900;font-size: 18px">软化点技术要求</span>
          <div class="display-right-btn">
            <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddSofteningPoint"></el-button>
          </div>
          <el-table border stripe class="table" v-loading="loading" style="width: 100%" :data="form.rhdRefs">
            <el-table-column label="序号" type="index" align="center" />
            <el-table-column label="温度下限(℃)" align="center" prop="min">
              <template slot-scope="scope">
                <el-input v-model="scope.row.min" placeholder="请输入" maxlength="40"></el-input>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
              <template slot-scope="scope">
                <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete2(scope.row, scope.$index)"
                  v-hasPermi="['xtcsgl:asphalt:remove']">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <!-- 延度 -->
        <div style="margin-top: 20px;">
          <span style="margin: 20px 0 8px 0;font-weight: 900;font-size: 18px">延度技术要求</span>
          <div class="display-right-btn">
            <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddDuctility"></el-button>
          </div>
          <el-table border stripe class="table" v-loading="loading" style="width: 100%" :data="form.ydRefs">
            <el-table-column label="序号" type="index" align="center" />
            <el-table-column label="温度" align="center" prop="temperature">
              <template slot-scope="scope">
                <el-input v-model="scope.row.temperature" placeholder="请输入" maxlength="40"></el-input>
              </template>
            </el-table-column>

            <el-table-column label="温度下限(℃)" align="center" prop="min">
              <template slot-scope="scope">
                <el-input v-model="scope.row.min" placeholder="请输入" maxlength="40"></el-input>
              </template>
            </el-table-column>

            <el-table-column label="延度下限(cm)" align="center" prop="min1">
              <template slot-scope="scope">
                <el-input v-model="scope.row.min1" placeholder="请输入" maxlength="40"></el-input>
              </template>
            </el-table-column>

            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
              <template slot-scope="scope">
                <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete3(scope.row, scope.$index)"
                  v-hasPermi="['xtcsgl:asphalt:remove']">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
<script>
import { listAsphalt, delSysAsphalt, addAsphalt, updateAsphalt, getSysAsphalt } from "@/api/xtcsgl/asphalt";
import { deptListData } from "@/api/zhgd/hntManage";
import { businessDeptTreeTop } from "@/api/common/common";

export default {
  name: "SysStation",
  dicts: ['asphalt_variety', 'asphalt_label', 'emulsified_asphalt', 'liquid_petroleum_asphalt', 'modified_asphalt', 'modified_emulsified_asphalt'],
  // 沥青种类: asphalt_variety
  // 沥青标号 道路石油沥青：asphalt_label 
  // 乳化沥青: emulsified_asphalt
  // 液体石油沥青: liquid_petroleum_asphalt 
  // 改性沥青: modified_asphalt
  // 改性乳化沥青: modified_emulsified_asphalt
  data() {
    return {
      id: '',
      radio: 0,
      // 字典
      dictVal: [],
      dictData1: '',
      dictData2: '',
      dictData3: '',
      dictData4: '',
      dictData5: '',
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 沥青技术要求表格数据
      asphaltList: [],
      // 工地名称列表数据
      constructionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        baseCode: undefined,
        type: undefined,
        name: undefined,
      },
      // 表单参数
      form: {
        refs: [],  //针入度
        rhdRefs: [], //软化点
        ydRefs: [],  //延度
      },
      deptList: [],
      // 表单校验
      rules: {
        deptId: [
          { required: true, message: '请选择项目名称', trigger: 'change' }
        ],
        asphaltVariety: [{ required: true, message: "沥青种类不能为空", trigger: "blur" }],
        asphaltLabel: [{ required: true, message: "沥青标号不能为空", trigger: "blur" }],
      }
    };
  },
  created() {
    this.getProjectList();
    this.getBusinessDeptTreeTop()
    this.getList();
    this.getDicts();
    // 字典 
    this.getDicts("asphalt_label").then((response) => {
      this.dictData1 = response.data  //道路石油沥青
      this.dictVal = response.data
    })
    this.getDicts("emulsified_asphalt").then((response) => {
      this.dictData2 = response.data  //乳化沥青
    })
    this.getDicts("liquid_petroleum_asphalt").then((response) => {
      this.dictData3 = response.data  //液体石油沥青
    })
    this.getDicts("modified_asphalt").then((response) => {
      this.dictData4 = response.data  //改性沥青
    })
    this.getDicts("modified_emulsified_asphalt").then((response) => {
      this.dictData5 = response.data  //改性乳化沥青
    })
  },
  methods: {
    // 项目名称
    getBusinessDeptTreeTop() {
      businessDeptTreeTop().then((res) => {
        this.deptList = res.data
      })
    },
    dictSelectChange(val) {
      if (val == "道路石油沥青") {
        this.dictVal = this.dictData1
      } else if (val == "乳化沥青") {
        this.dictVal = this.dictData2
      } else if (val == "液体石油沥青") {
        this.dictVal = this.dictData3
      } else if (val == "改性沥青") {
        this.dictVal = this.dictData4
      } else if (val == "改性乳化沥青") {
        this.dictVal = this.dictData5
      } else if (val == "煤沥青") {
        this.dictVal = []
      }
    },
    /** 查询沥青技术要求列表 */
    getList() {
      this.loading = true;
      listAsphalt(this.queryParams).then(response => {
        this.asphaltList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 查询工地名称列表 */
    getProjectList() {
      deptListData().then((response) => {
        this.constructionList = response
      })
    },
    changeProjectCatalog(val) {
      if (val != undefined) {
        if (val.length > 0) {
          this.form.projectCatalog = val[val.length - 1];
        } else {
          this.form.projectCatalog = null;
        }
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        baseCode: undefined,
        type: undefined,
        name: undefined,
        asphaltVariety: undefined,
        refs: [],  //针入度
        rhdRefs: [], //软化点
        ydRefs: [],  //延度
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加沥青技术要求";
      this.dictVal = this.dictData1
    },
    // 针入度技术要求添加   
    handleAddPenetration() {
      this.form.refs.push({
        temperature: "",
        max: "",
        min: "",
      });
    },
    // 软化点技术要求添加 
    handleAddSofteningPoint() {
      this.form.rhdRefs.push({
        temperature: "",
      });
    },
    // 延度技术要求添加    
    handleAddDuctility() {
      this.form.ydRefs.push({
        temperature: "",
        min: "",
        max: "",
        min1: "",
        min2: "",
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.open = true;
      const id = row.id || this.ids
      getSysAsphalt(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改沥青技术要求";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateAsphalt(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addAsphalt(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row, index) {
      const ids = row.id || this.ids;
      this.$modal.confirm(row.id ? `是否确认删除序号为"${index + 1}"的数据项？` : '是否确认删除选中数据项？').then(() => {
        this.loading = true;
        return delSysAsphalt(ids);
      })
        .then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {
        }).finally(() => {
          this.loading = false;
        });
    },
    // 针入度删除
    handleDelete1(row, index) {
      this.$modal.confirm(`是否确认删除序号为"${index + 1}"的数据项？`).then(() => {
        return this.form.refs.splice(index, 1);
      }).then(() => {
        this.$modal.msgSuccess("删除成功");
      })
    },
    // 软化点删除
    handleDelete2(row, index) {
      this.$modal.confirm(`是否确认删除序号为"${index + 1}"的数据项？`).then(() => {
        return this.form.rhdRefs.splice(index, 1);
      }).then(() => {
        this.$modal.msgSuccess("删除成功");
      })
    },
    // 延度删除
    handleDelete3(row, index) {
      this.$modal.confirm(`是否确认删除序号为"${index + 1}"的数据项？`).then(() => {
        return this.form.ydRefs.splice(index, 1);
      }).then(() => {
        this.$modal.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('zhgd/sysStation/export', {
        ...this.queryParams
      }, `sysStation_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
  
<style lang="scss" scoped>
::v-deep .query {
  .el-form-item__label {
    width: 110px !important;
  }
}

.display-right-btn {
  float: right;
}

::v-deep .table {
  .el-form-item__content {
    margin-left: 0px !important;
  }
}
</style>






  